using System;
using DirkRettschlag.Utils;
using System.Drawing;


namespace Departure
{
    public class SkinSettings
    {
        #region Variables

        string skinFile;

        bool hasLoadErrors;

        Settings settings;
        Color fontColor;
        Color laterColor;
        bool boldTime;
        bool boldTrain;

        string backGroundItemPath;
        Bitmap backGroundItem;
        string backGroundItemSelectedPath;
        Bitmap backGroundItemSelected;
        string backGroundPath;
        Bitmap backGround;
        string fastAccessPath;
        Bitmap fastAccess;

        string fastAccessWidePath;
        Bitmap fastAccessWide;
        
        string backGroundButtonPath;
        Bitmap backGroundButton;

        string backGroundButtonSelectedPath;
        Bitmap backGroundButtonSelected;

        string buttonListPath;
        string buttonBackPath;
        string buttonUpdatePath;
        string buttonStopPath;
        string buttonMenuPath;
        string buttonCountdownPath;
        string buttonEmptyPath;

        string backGroundHeaderPath;
        Bitmap backGroundHeader;

        string backGroundStatusPath;
        Bitmap backGroundStatus;

        #endregion Variables
                     
        #region Properties

        public string SkinFile
        {
            get { return this.skinFile; }
            set { this.skinFile = value; }
        }

        public bool BoldTrain
        {
            get { return this.boldTrain; }
            set { this.boldTrain = value; }
        }

        public bool BoldTime
        {
            get { return this.boldTime; }
            set { this.boldTime = value; }
        }

        public System.Drawing.Color LaterColor
        {
            get { return this.laterColor; }
            set { this.laterColor = value; }
        }

        public System.Drawing.Color FontColor
        {
            get { return this.fontColor; }
            set { this.fontColor = value; }
        }

        public System.Drawing.Bitmap BackGroundItem
        {
            get { return this.backGroundItem; }
            set { this.backGroundItem = value; }
        }

        public System.Drawing.Bitmap BackGroundItemSelected
        {
            get { return this.backGroundItemSelected; }
            set { this.backGroundItemSelected = value; }
        }

        public System.Drawing.Bitmap BackGround
        {
            get { return this.backGround; }
            set { this.backGround = value; }
        }

        public System.Drawing.Bitmap FastAccess
        {
            get { return this.fastAccess; }
            set { this.fastAccess = value; }
        }

        public System.Drawing.Bitmap FastAccessWide
        {
            get { return this.fastAccessWide; }
            set { this.fastAccessWide = value; }
        }

        public System.Drawing.Bitmap BackGroundButton
        {
            get { return this.backGroundButton; }
            set { this.backGroundButton = value; }
        }

        public System.Drawing.Bitmap BackGroundButtonSelected
        {
            get { return this.backGroundButtonSelected; }
            set { this.backGroundButtonSelected = value; }
        }

        public String ButtonListPath
        {
            get { return this.buttonListPath; }
            set { this.buttonListPath = value; }
        }

        public String ButtonBackPath
        {
            get { return this.buttonBackPath; }
            set { this.buttonBackPath = value; }
        }

        public String ButtonUpdatePath
        {
            get { return this.buttonUpdatePath; }
            set { this.buttonUpdatePath = value; }
        }

        public String ButtonStopPath
        {
            get { return this.buttonStopPath; }
            set { this.buttonStopPath = value; }
        }

        public String ButtonMenuPath
        {
            get { return this.buttonMenuPath; }
            set { this.buttonMenuPath = value; }
        }

        public String ButtonCountdownPath
        {
            get { return this.buttonCountdownPath; }
            set { this.buttonCountdownPath = value; }
        }

        public String ButtonEmptyPath
        {
            get { return this.buttonEmptyPath; }
            set { this.buttonEmptyPath = value; }
        }

        public System.Drawing.Bitmap BackGroundHeader
        {
            get { return this.backGroundHeader; }
            set { this.backGroundHeader = value; }
        }

        public System.Drawing.Bitmap BackGroundStatus
        {
            get { return this.backGroundStatus; }
            set { this.backGroundStatus = value; }
        }

        public bool HasLoadErrors
        {
            get { return this.hasLoadErrors;}
            set { this.hasLoadErrors = value; }
        }

        #endregion Properties

        #region Constructor

        public SkinSettings()
        {
            backGround = new Bitmap(240, 320);
            backGroundItem = new Bitmap(240, 46);
            backGroundItemSelected = new Bitmap(240, 46);
            fastAccess = new Bitmap(80, 40);
            fastAccessWide = new Bitmap(160, 40);
            backGroundButton = new Bitmap(32, 32);
            backGroundButtonSelected = new Bitmap(32, 32);
            backGroundHeader = new Bitmap(240, 32);
            backGroundStatus = new Bitmap(240, 32);
        }

        public SkinSettings(string SkinFile): this()
        {
            this.skinFile = SkinFile;
        }

        #endregion Constructor

        #region Public Methods

        public void saveSettings()
        {
            settings = new Settings(Utilities.AppPath() + "\\skins\\" + skinFile);
            settings.WriteColor("Main", "FontColor", fontColor);
            settings.WriteColor("Main", "LaterColor", laterColor);
            settings.WriteBool("Main", "BoldTime", boldTime);
            settings.WriteBool("Main", "BoldTrain", boldTrain);
            settings.WriteString("Main", "BackGround", backGroundPath);
            settings.WriteString("Main", "BackGroundItem", backGroundItemPath);
            settings.WriteString("Main", "BackGroundItemSelected", backGroundItemSelectedPath);
            settings.WriteString("Main", "FastAccess", fastAccessPath);
            settings.WriteString("Main", "FastAccessWide", fastAccessWidePath);
            settings.WriteString("Main", "BackGroundButton", backGroundButtonPath);
            settings.WriteString("Main", "BackGroundButtonSelected", backGroundButtonSelectedPath);
            settings.WriteString("Main", "ButtonList", buttonListPath);
            settings.WriteString("Main", "ButtonBack", buttonBackPath);
            settings.WriteString("Main", "ButtonUpdate", buttonUpdatePath);
            settings.WriteString("Main", "ButtonStop", buttonStopPath);
            settings.WriteString("Main", "ButtonMenu", buttonMenuPath);
            settings.WriteString("Main", "ButtonCountdown", buttonCountdownPath);
            settings.WriteString("Main", "ButtonEmpty", buttonEmptyPath);
            settings.WriteString("Main", "BackGroundHeader", backGroundHeaderPath);
            settings.WriteString("Main", "BackGroundStatus", backGroundStatusPath);

            settings.Save();

        }

        public void getSettings()
        {

            settings = new Settings(Utilities.AppPath() + "\\skins\\" + skinFile);
            fontColor = settings.ReadColor("Main", "FontColor", Color.Black);
            laterColor = settings.ReadColor("Main", "LaterColor", Color.Red);
            boldTime = settings.ReadBool("Main", "BoldTime", false);
            boldTrain = settings.ReadBool("Main", "BoldTrain", false);
            backGroundPath = settings.ReadString("Main", "BackGround", "");
            backGroundItemPath = settings.ReadString("Main", "BackGroundItem", "");
            backGroundItemSelectedPath = settings.ReadString("Main", "BackGroundItemSelected", "");
            fastAccessPath = settings.ReadString("Main", "FastAccess", "");
            fastAccessWidePath = settings.ReadString("Main", "FastAccessWide", "");
            backGroundButtonPath = settings.ReadString("Main", "BackGroundButton", "");
            backGroundButtonSelectedPath = settings.ReadString("Main", "BackGroundButtonSelected", "");
            buttonListPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonList", "");
            buttonBackPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonBack", "");
            buttonUpdatePath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonUpdate", "");
            buttonStopPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonStop", "");
            buttonMenuPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonMenu", "");
            buttonCountdownPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonCountdown", "");
            buttonEmptyPath = Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + settings.ReadString("Main", "ButtonEmpty", "");
            backGroundHeaderPath = settings.ReadString("Main", "BackGroundHeader", "");
            backGroundStatusPath = settings.ReadString("Main", "BackGroundStatus", "");

            try
            {
                backGround = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundPath);
                backGroundItem = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundItemPath);
                backGroundItemSelected = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundItemSelectedPath);
                fastAccess = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + fastAccessPath);
                fastAccessWide = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + fastAccessWidePath);
                backGroundButton = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundButtonPath);
                backGroundButtonSelected = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundButtonSelectedPath);
                backGroundHeader = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundHeaderPath);
                backGroundStatus = new Bitmap(Utilities.AppPath() + "\\skins\\" + skinFile.Replace(".skin", "\\") + backGroundStatusPath);
            }
            catch
            {
                this.hasLoadErrors = true;
            }

        }

        #endregion Public Methods

    }
}
